Added allocateDeviceID, which uses the store to keep track of per-domain,
authoremellor@ewan <emellor@ewan>
Sun, 18 Sep 2005 17:18:52 +0000 (18:18 +0100)
committeremellor@ewan <emellor@ewan>
Sun, 18 Sep 2005 17:18:52 +0000 (18:18 +0100)
per-device-class device IDs on behalf of the DevController subclasses.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/server/DevController.py

index f315f0470bc8c6f0bc730ac7970abc134acaac45..f8fe749ffceee31b8c54d65074a972f665bb5242 100644 (file)
@@ -117,6 +117,31 @@ class DevController:
         return self.vm.getDomain()
 
 
+    def allocateDeviceID(self):
+        """Allocate a device ID, allocating them consecutively on a
+        per-domain, per-device-class basis, and using the store to record the
+        next available ID.
+
+        This method is available to our subclasses, though it is not
+        compulsory to use it; subclasses may prefer to allocate IDs based upon
+        the device configuration instead.
+        """
+        path = self.frontendMiscPath()
+        t = xstransact(path)
+        try:
+            result = t.read("nextDeviceID")
+            if result:
+                result = int(result)
+            else:
+                result = 1
+            t.write("nextDeviceID", str(result + 1))
+            t.commit()
+            return result
+        except:
+            t.abort()
+            raise
+
+
     ## private:
 
     def writeDetails(self, config, devid, backDetails, frontDetails):
@@ -170,6 +195,9 @@ class DevController:
 
 
     def frontendPath(self, devid):
-        return "%s/device/%s/%d" % (self.vm.getPath(),
-                                    self.deviceClass,
+        return "%s/device/%s/%d" % (self.vm.getPath(), self.deviceClass,
                                     devid)
+
+
+    def frontendMiscPath(self):
+        return "%s/device-misc/%s" % (self.vm.getPath(), self.deviceClass)